package com.quanquan.repository;

import com.quanquan.entity.LessonInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface LessonInfoRepository extends JpaRepository<LessonInfo, Long>,JpaSpecificationExecutor<LessonInfo> {

    LessonInfo findById(long id);

    Long deleteById(Long id);

    List<LessonInfo> findByGrade(String grade);

    Page<LessonInfo> findAll(Pageable pageable);

    List<LessonInfo> findByLessonNameContaining(String lessonName);

    @Query(nativeQuery = true, value = "SELECT * FROM lesson_info WHERE grade_ = ?1 and id > ?2 LIMIT 10")
    List<LessonInfo> findLesson(String grade,Long id);

    @Query(nativeQuery = true, value = "SELECT COUNT(*) FROM lesson_info WHERE grade_ like %?1%")
    Long countLesson(String grade);

    Page<LessonInfo> findAllByGradeLike(String grade, Pageable pageable);

    @Query(nativeQuery = true, value = "SELECT * FROM lesson_info WHERE lesson_name like %?1% OR teacher_name LIKE %?1%")
    List<LessonInfo> findKeywords(String keyword);

    List<LessonInfo> findAll();
}